package org.elanfox.intellicommunity.msg.server.mq;

import lombok.extern.slf4j.Slf4j;
import org.elanfox.intellicommunity.msg.constant.MsgConstant;
import org.elanfox.intellicommunity.msg.dto.CmdDTO;
import org.elanfox.intellicommunity.msg.dto.RawTagDTO;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @author allan
 * @version 1.0.0
 * @date 2019/12/12
 */
@Service
@Slf4j
public class MsgProvider {
    @Autowired
    private RabbitTemplate template;

    public void sendLocationMsg(RawTagDTO rawMsgDTO) {
        Map<String, Object> msgMap = new HashMap<>();
        msgMap.put("msg", rawMsgDTO);
        log.info("发送标签信息=====>" + rawMsgDTO.toString());
        template.convertAndSend(MsgConstant.EXCHANGE_MESSAGE, MsgConstant.QUEUE_LOCATION, msgMap);
    }

    public void sendAlarmMsg(RawTagDTO rawMsgDTO) {
        Map<String, Object> msgMap = new HashMap<>();
        msgMap.put("msg", rawMsgDTO);
        template.convertAndSend(MsgConstant.EXCHANGE_MESSAGE, MsgConstant.QUEUE_ALARM, msgMap);
    }

    public void sendCommandResp(CmdDTO cmdDTO) {
        Map<String, Object> msgMap = new HashMap<>();
        msgMap.put("msg", cmdDTO);
        template.convertAndSend(MsgConstant.EXCHANGE_MESSAGE, MsgConstant.QUEUE_COMMAND_RESP, msgMap);
    }
}
